setwd("/home/jc227089/SRE/KB/DispOnly/limits/")

K<-seq(1, 50, 5)
lmda<-seq(2, 52, 5)

script.file<-"/home/jc227089/evo-dispersal/KBGrad/DispOnly/limits/KbyL/K_by_lambda.R"
fname<-"Kbyl_limits"

for (ii in 1:length(K)) {
	for (jj in 1:length(lmda)){
		fid<-jj+(ii-1)*length(K)
		##create the sh file
		zz = file(paste(fname, fid,'.sh',sep=''),'w')
		cat('##################################\n',file=zz)
		cat('#!/bin/sh\n',file=zz)
		cat('cd $PBS_O_WORKDIR\n',file=zz)
		cat("R CMD BATCH --no-save --no-restore '--args fID=",fid, " K=", K[ii], " lmda=", lmda[jj], "' ", sep="", file=zz)
		cat(script.file, " ", paste(fname, fid,'.Rout',sep=''), "\n", sep="",file=zz)
		cat('##################################\n',file=zz)
		close(zz)
				
		#submit the job
		system(paste("qsub -m n ", paste(fname, fid,".sh",sep=""),sep=""))
	}
}
